import java.util.*;

/**
 * 输入整形数组和排序标识，对其元素按照升序或降序进行排列
 */
public class ArraySorted {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int num = scanner.nextInt();
            List<Integer> numList = new ArrayList<>();
            for (int i=0; i<num; i++) {
                numList.add(scanner.nextInt());
            }
            int order = scanner.nextInt();
            if (order == 0) {
                // 升序
                numList.sort(new Comparator<Integer>() {
                    @Override
                    public int compare(Integer o1, Integer o2) {
                        return o1.compareTo(o2);
                    }
                });
            } else {
                // 降序
                numList.sort(new Comparator<Integer>() {
                    @Override
                    public int compare(Integer o1, Integer o2) {
                        return o2.compareTo(o1);
                    }
                });
            }
            numList.forEach(num1 -> System.out.print(num1 + " "));
            System.out.println();
        }
    }
}
